package com.keelau.ui.swing;


/*
import com.intellij.uiDesigner.ui.GridConstraints;
import com.intellij.uiDesigner.ui.GridLayoutManager;
import com.intellij.uiDesigner.ui.Spacer;

*/

import com.keelau.config.AutoConfig;
import com.keelau.idao.model.AliCatalog;
import com.keelau.ui.bind.MyListCellRenderer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.inject.Inject;
import javax.inject.Named;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

@Named
public class MainForm {
    private JPanel aliPanel;
    private JTextField textField1;
    private JButton btnGet;
   // @Inject
    FxBrowerUI fxBrowerUI;


    //static MainForm mainForm;

    //region Getter
    public JPanel getAliPanel() {
        return aliPanel;
    }

    public JTextField getTextField1() {
        return textField1;
    }

    public JButton getBtnGet() {
        return btnGet;
    }

    public JList getList1() {
        return list1;
    }

    public JPanel getBottomPanel() {
        return bottomPanel;
    }

    public JPanel getTopPanel() {
        return topPanel;
    }

    public JTable getTable1() {
        return table1;
    }
    //endregion

    private JList list1;
    private JPanel bottomPanel;
    private JPanel topPanel;
    private JTable table1;
    JFrame frame;

    public JFrame getFrame() {
        return frame;
    }

    public MainForm() {
        initUI();
        frame = new JFrame("mainForm");
        frame.setBounds(340, 100, 800, 800);
        frame.setContentPane(aliPanel);
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.pack();
        //frame.setVisible(true);
    }

    /*
    手动创建UI Component;
     */
    private void createUIComponents() {
        // TODO: place custom component creation code here
        list1 = new JList<AliCatalog>();


    }

    private void initUI() {
        DefaultListModel<AliCatalog> defaultListModel = new DefaultListModel<>();
        AliCatalog aliCatalog = new AliCatalog();
        aliCatalog.setId(1L);
        aliCatalog.setName("test1");
        AliCatalog aliCatalog1 = new AliCatalog();
        aliCatalog1.setId(2L);
        aliCatalog1.setName("test2");
        defaultListModel.addElement(aliCatalog);
        defaultListModel.addElement(aliCatalog1);
        list1.setCellRenderer(new MyListCellRenderer());
        //list1.setListData(new String[]{"abc", "fdsafd", "fdsaf", "fdsafd", "fdsafd", "jfksdlafd"});
        list1.setModel(defaultListModel);

        addListener();
    }

    public void addListener() {
        btnGet.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fxBrowerUI.getFrame().setVisible(true);
            }
        });
    }


    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AutoConfig.class);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                MainForm mainForm = context.getBean(MainForm.class);
                mainForm.getFrame().setVisible(true);
            }
        });
    }

}
